﻿namespace System.ServiceModel.DomainServices
{
    using System;
    using System.Runtime.CompilerServices;
    using System.Threading;

    internal static class ExceptionHandlingUtility
    {
        public static bool IsFatal(this Exception exception)
        {
            while (exception != null)
            {
                if (IsFatalExceptionType(exception))
                {
                    return true;
                }
                exception = exception.InnerException;
            }
            return false;
        }

        private static bool IsFatalExceptionType(Exception exception)
        {
            if (!(exception is ThreadAbortException) && (!(exception is OutOfMemoryException) || (exception is InsufficientMemoryException)))
            {
                return false;
            }
            return true;
        }
    }
}

